
/*
 * trf7960.c
 *
 * Created: 21.02.2013 10:15:16
 *  Author: saenko
 */ 
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "SPI_M.h"
#include "HEXtoASCII.h"


void trf7960_init(void)
{
	EICRA = (1<<ISC01)|(1<<ISC00);
	EIMSK = (1<<INT0);
}



ISR(INT0_vect)
{
	unsigned char temp;
	temp = spi_read_IRQ_status();
	putchr(13);
	if(bit_is_set(temp,7)) putchr('T');
	else putchr('_');
	
	if(bit_is_set(temp,6)) putchr('R');
	else putchr('_');
	
	if(bit_is_set(temp,5)) putchr('F');
	else putchr('_');
	
	if(bit_is_set(temp,4)) putchr('C');
	else putchr('_');
	
	if(bit_is_set(temp,3)) putchr('P');
	else putchr('_');
	
	if(bit_is_set(temp,2)) putchr('F');
	else putchr('_');
	
	if(bit_is_set(temp,1)) putchr('E');
	else putchr('_');
	
	if(bit_is_set(temp,0)) putchr('N');
	else putchr('_');
	
	putchr(13);
}

void load_to_fifo(unsigned char data)
{
	spi_write_reg(0x1F,data);
}

void read_fifo_set(void)
{
	unsigned char temp;
	temp = spi_read_reg(0x5C);
	if(bit_is_set(temp,7)) printstr_p(PSTR("9 bits\n"));
	if(bit_is_set(temp,6)) printstr_p(PSTR("3 bits\n"));
	if(bit_is_set(temp,5)) printstr_p(PSTR("fifo if full\n"));
	
	hex_to_ascii(temp&0b00001111);
	putchr(ascii_hi);
	putchr(ascii_low);
	printstr_p(PSTR(" bits in fifo\n"));
	
	temp = spi_read_reg(0x5D);
	hex_to_ascii(temp);
	printstr_p(PSTR("0x0"));	
	putchr(ascii_hi);
	putchr(ascii_low);	
		
	temp = spi_read_reg(0x5E);
	hex_to_ascii(temp);
	putchr(ascii_hi);
	printstr_p(PSTR(" wqe\n"));
	
}

//--------------------------------------
void cmd_idle(void)
{
	spi_write(0x80);	
}

void cmd_soft_init(void)
{
	spi_write(0x83);
}

void cmd_reset(void)
{
	spi_write(0x8F);
}

void cmd_trans_without_crc(void)
{
	spi_write(0x90);
}

void cmd_trans_with_crc(void)
{
	spi_write(0x91);
}

void cmd_del_trans_without_crc(void)
{
	spi_write(0x92);
}

void cmd_del_trans_with_crc(void)
{
	spi_write(0x93);
}

void cmd_trans_next_slot(void)
{
	spi_write(0x94);
}

void cmd_block_rec(void)
{
	spi_write(0x96);
}

void cmd_enable_rec(void)
{
	spi_write(0x97);
}

void cmd_test_int_rf(void)
{
	spi_write(0x98);
}

void cmd_text_ext_rf(void)
{
	spi_write(0x99);
}

void cmd_rec_gain_adjust(void)
{
	spi_write(0x9A);
}

//-------------------

